import http from './http'

export async function getCities(params = {}) {
  const { data } = await http.get('/api/cities', { params })
  return Array.isArray(data?.data) ? data.data : []
}

export async function getCityById(id) {
  const { data } = await http.get(`/api/cities/${id}`)
  return data?.data || null
}

export async function createCity(payload) {
  const { data } = await http.post('/api/cities', payload)
  return data?.data
}

export async function updateCity(id, payload) {
  const { data } = await http.put(`/api/cities/${id}`, payload)
  return data?.data
}

export async function deleteCity(id) {
  const { data } = await http.delete(`/api/cities/${id}`)
  return !!data?.success
}

export async function recommendCity(id) {
  const { data } = await http.post(`/api/cities/${id}/recommend`)
  return data
}